﻿package Interface.TracksClasses
{	
	import Interface.ArrowsScroller;
	import GameUtils.TrackData;
	
	import flash.events.MouseEvent;	
	import flash.text.TextField;

	public class TracksScroller extends ArrowsScroller
	{
		private var FPagesCount:int;
		private var FCurrentPage:int;
		private var FContainer:TracksScrollerContainer;
		private var FData:Vector.<TrackData>;
		private var FItems:Vector.<TrackLabel>;
		
		public function TracksScroller():void
		{
			super();
			FItems = new Vector.<TrackLabel>;
			FPagesCount = 0;
			FCurrentPage = 0;
			
			FContainer = getChildByName('Container') as TracksScrollerContainer;
			
			FUp.enabled = false;
			FDown.enabled = false;
		}
		
		override protected function OnUp(e:MouseEvent):void
		{
			if (e.target.enabled)
			{				
				FContainer.MoveUp();
				FUp.enabled = !FContainer.IsFirstPage;
				FDown.enabled = !FContainer.IsLastPage;
			}
		}
		
		override protected function OnDown(e:MouseEvent):void
		{
			if (e.target.enabled)
			{				
				FContainer.MoveDown();
				FUp.enabled = !FContainer.IsFirstPage;
				FDown.enabled = !FContainer.IsLastPage;
			}
		}
		
		public function set Data(AData:Vector.<TrackData>):void
		{
			FData = AData;
			var vText:TextField;
			for(var i in FData)
			{
				var vLabel:TrackLabel = new TrackLabel(FData[i]);				
				vLabel.Data = FData[i];
				FItems.push(vLabel);
				FContainer.AddItem(vLabel);
			}
			
			FDown.enabled = FData.length > 7;
		}
		
		public function get Items():Vector.<TrackLabel>
		{
			return FItems;
		}		
	}	
}
